package org.example.myportfolio.dao.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.example.myportfolio.dao.mapper.WorkTagsMapper;
import org.example.myportfolio.dao.repository.WorkTagsRepository;
import org.example.myportfolio.pojo.po.WorkTagsPO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Slf4j
@Repository("workTagsRepository")
public class WorkTagsRepositoryImpl implements WorkTagsRepository {


    @Autowired
    private WorkTagsMapper tagMapper;


    @Override
    public void saveTag2Work(int tagId, Long workId) {
        log.debug("tagId:{},workId:{}",tagId,workId);
        QueryWrapper<WorkTagsPO> queryWrapper = new QueryWrapper<>();
        WorkTagsPO workTagsPO = new WorkTagsPO();
        workTagsPO.setTagId(tagId);
        workTagsPO.setWorkId(workId);
        try {
            tagMapper.insert(workTagsPO);
        } catch (Exception e) {
            log.error("作品标签插入失败:{}",e.getMessage(),e);
            throw new RuntimeException("作品标签插入失败",e);
        }
    }
}
